var n;
var t = getApp().http.anchor_mailistPost;
var historyJiekou = getApp().http.historyPost //接口历史记录
var util = getApp().util;
Page({
    data: {
      upzhuchi:0
    },
    onLoad: function(n) {
         this.getmaiList();
    },
    onReady: function() {},
    onShow: function() {
        n = setInterval(function() {
            this.getmaiList(!1);
        }.bind(this), "2000");
      
      let uid = wx.getStorageSync("userinfo").uid //用户
      let manager_id = wx.getStorageSync("dangqiInfo").manager_id //主持人
      //判断跳转页面
      if (manager_id == uid || wx.getStorageSync("userinfo").roles.indexOf("1") > -1 ){
        wx.redirectTo({
          url: '../main_daka/main_daka'
        })
      }
       
      //显示 是否修改主持人操作
      var endtime = wx.getStorageSync('dangqiInfo').riqi + " " + wx.getStorageSync('dangqiInfo').endtime
      if (new Date().getTime() < (util.riqiTime(endtime)) && uid != manager_id) {
           this.setData({
             upzhuchi:1
           })
      }
    },
    onHide: function() {
        clearInterval(n);
    },
    onUnload: function() {
        clearInterval(n);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = n.riqi + " " + n.endtime;
        if (new Date().getTime() > util.riqiTime(t)) i = "直播已结束"; else var i = "直播中";
        return util.shareSet(this, i);
    },
    getmaiList: function() {
        var n = this, i = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0], e = wx.getStorageSync("dangqiInfo"), o = wx.getStorageSync("userinfo").token, a = e.starttime + " — " + e.endtime;
        wx.setNavigationBarTitle({
            title: a
        }), t({
            token: o,
            dangqiid: e.id
        }, i).then(function(t) {
            0 == t.code ? (1 == t.add_status && wx.redirectTo({
                url: "../anchor_budang/anchor_budang"
            }), n.setData({
                maiList: t.data,
                dangqiInfo: e,
                beteenTime: a,
                addStatus: Number(t.addinbtn)
            })) : console.log("接口返回数据失败", t);
        });
    },
  //更换主持人
  updatemainUrl() {
    // 是否超过档期结束时间
    var endtime = wx.getStorageSync('dangqiInfo').riqi + " " + wx.getStorageSync('dangqiInfo').endtime
    if (new Date().getTime() > (util.riqiTime(endtime))) {
      wx.showToast({
        title: '直播已经结束不能更换主持',
        icon: 'none'
      })
    } else {
      let dangqiInfo = wx.getStorageSync("userinfo")
      if (dangqiInfo.roles.indexOf("1") > -1) {
        wx.navigateTo({
          url: "../xcx_chair/xcx_chair"
        });
      } else {
        wx.navigateTo({
          url: "../xcx_chairChange/xcx_chairChange"
        });
      }

    }
  },
   //历史记录
   bindhistory(){
    var that = this
    var token = wx.getStorageSync('userinfo').token;
    var qid = wx.getStorageSync('dangqiInfo').id
    historyJiekou({
        token,
        qid,
    },false).then(res=>{
          if(res.code == 0){
             that.setData({
                 Historylist:res.data,
                 mask:1
             })
          }
    })
  },
});